<?php
global $db, $title_bar, $cat, $lg, $title_page, $num_of_result, $num_of_articles;

if(isset($_GET['cat1'])){
		global $cat1;
		$id = $cat1['id'];
		
		$title_bar = $cat1["name_$lg"];
		
		$title_page = $cat1["title_$lg"]; 
		
		$cat = $cat1;
			
		//lay cac muc con
		$sql = "SELECT c.desc_vn, c.desc_en, c.name_vn, c.name_en, c.unique_key_vn, c.unique_key_en, c.comp, c.des_vn, c.des_en, c.img, (select count(id) from products WHERE cid = c.id) as num_of_result_products, (select count(id) from articles WHERE cid=c.id) as num_of_articles, (select sum(view) from products where cid = c.id) as total_product_views, (select sum(view) from articles where cid = c.id) as total_article_views FROM categories c WHERE pid = $id ORDER BY num asc, id asc";
		
		$submenus = $db->getAll($sql);
}else{
	$id = CleanSQLInjection(trim(isset($_GET['cid'])?$_GET['cid']:''));
	
	//lay chi tiet the loai
	$sql = "select * from categories where id=".$id;
	$cat = $db->getRow($sql);
	
	$title_bar = $cat['name_' . $_SESSION['lg']];
	
	//lay cac muc con
	$sql="SELECT * FROM categories WHERE pid=$id ORDER BY num asc, id asc";
	$submenus = $db->getAll($sql);
}
//show
$tpl="list";
?>